package me.leiusual.sharing.ui.mine.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.view_holder_mine_message.*
import me.leiusual.sharing.api.model.UserMessage
import me.leiusual.sharing.util.extension.toSpanned

/**
 * author: leiusual
 * create on: 2019-08-04
 * description:
 */
class MineMessageViewHolder(
    override val containerView: View
) : RecyclerView.ViewHolder(containerView), LayoutContainer {

  fun bind(userMessage: UserMessage) {

    // 类型、内容
    val builder = StringBuilder()
    builder.append(userMessage.msgTypeName)
    builder.append(if (userMessage.viewed) "" else "（未读）")
    builder.append("""<br/>""")
    builder.append(userMessage.message)
    text_view.text = builder.toString().toSpanned()

    // 发送者
    text_view_sender.text = userMessage.senderName

    // 是否发送短信
    if (userMessage.enableSm) {
      text_view_sender.append(""" ${if (userMessage.send) "已发短信" else "未发短信"}""")
    }

    // 时间
    text_view_date.text = userMessage.createTime
  }
}